package com.tjetc.file;

import org.junit.jupiter.api.Test;

import java.io.*;

public class _2Directory {
    /*
        1. mkdir创建⼀级⽬录
        2. mkdirs创建多级⽬录
        3. delete删除空⽬录或⽂件

        windows： \\  linux/macos：/
     */
    @Test
    public void testCreateDirectory() {
        File file = new File("/Users/gaoyongxiang/百度网盘/IDEA-Java/202507-java-se/chapter16/src/com/tjetc/file/a");
        file.mkdir();
    }

    @Test
    public void testCreateMoreDirectory() {
        File file = new File("/Users/gaoyongxiang/百度网盘/IDEA-Java/202507-java-se/chapter16/src/com/tjetc/file/b/a");

        System.out.println("file.mkdirs() = " + file.mkdirs());
    }

    @Test
    public void testDeleteFile() {
        File file = new File("/Users/gaoyongxiang/百度网盘/IDEA-Java/202507-java-se/chapter16/1.txt");
        if (file.exists()) {
            System.out.println("file.delete() = " + file.delete());
        }

    }

    @Test
    public void testDeleteDirectory() {
        File file = new File("/Users/gaoyongxiang/百度网盘/IDEA-Java/202507-java-se/chapter16/src/com/tjetc/file/b");
        if (file.exists()) {
            // 删除目录只能删除一级
            // 删除的目录必须是空目录
            System.out.println("file.delete() = " + file.delete());
        }
    }


    @Test
    public void testFileMethod(){
        String filePath = "/Users/gaoyongxiang/百度网盘/IDEA-Java/202507-java-se/chapter16";
        String fileName = "3.txt";
        File file1 = new File(filePath, fileName);
        //调⽤相应的⽅法，得到对应信息
        //getName、getAbsolutePath、getParent、length、exists、isFile、isDirectory
        System.out.println("⽂件名字=" + file1.getName());
        System.out.println("⽂件绝对路径=" + file1.getAbsolutePath());
        System.out.println("⽂件⽗级⽬录=" + file1.getParent());
        System.out.println("⽂件⼤⼩(字节)=" + file1.length());
        System.out.println("⽂件是否存在=" + file1.exists());
        System.out.println("是不是⼀个⽂件=" + file1.isFile());
        System.out.println("是不是⼀个⽬录=" + file1.isDirectory());
    }

}
